package com.opesoft.calendar.biz;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.Cookie;

import com.opesoft.fw.ajax.AjaxWebManager;

public class DateUtils
{
	final static String NoteTypesInCookie="_noteTypes";
	final static String NoteTypesInCookieSeparater="_";

	static public String intDate2Str(int year,int month,int day)
	{
		return ""+year+(month<10?"0"+(month+1):month+1)+(day<10?"0"+day:day);
	}

	static public Long[] getNoteTypesFromCookie()
	{
		Cookie[] cookies=AjaxWebManager.request().getCookies();
		if(cookies!=null&&cookies.length>0)
		{
			for(int j=cookies.length-1;j>-1;j--)
			{
				Cookie cookie=cookies[j];
				if(NoteTypesInCookie.equals(cookie.getName()))
				{
					String value=cookie.getValue();
					if(value!=null&&value.length()>0)
					{
						String[] strArray=value.split(NoteTypesInCookieSeparater);
						if(strArray!=null&&strArray.length>0)
						{
							// long[] result=new long[strArray.length];
							List list=new ArrayList();
							for(int i=0;i<strArray.length;i++)
							{
								try
								{
									list.add(Long.valueOf(strArray[i]));
								}
								catch(Exception e)
								{}
							}

							Long[] result=new Long[list.size()];
							list.toArray(result);
							return result;
						}
					}

					break;
				}
			}
		}

		return new Long[0];
	}
}
